package site.immonkey.mytool;

public class Deadlock {
	final static byte[] l1 = new byte[0];
	final static byte[] l2 = new byte[0];
	static Thread t1, t2;

	public static void main(String[] args) throws Exception {
		t1 = new Thread1(); 
		t1.start();

		Thread.sleep(1000);

		t2 = new Thread2();
		t2.start();
	}

	static class Thread1 extends Thread {
		@Override
		public void run() {
			synchronized (l1) {
				synchronized (this) {
					try {
						wait();
					} catch (InterruptedException e) {}
				}
				synchronized (l2) {
					System.out.println("t1");
				}
			}
		}
	}

	static class Thread2 extends Thread {
		@Override
		public void run() {
			synchronized (l2) {
				synchronized (t1) {
					t1.notify();
				}
				synchronized (l1) {
					System.out.println("t2");
				}
			}
		}
	}
}
